﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dao;
using common;
using System.Resources;
using System.Globalization;

namespace GTVAccountingSystem.view.form
{
    public partial class frmAuditlog : Form
    {
        AuditLogDAO auditLogDAO = new AuditLogDAO();
        frmMain main;
        public String username = "";
        public String fromDate = "";
        public String endDate = "";
        public DataTable dt;
        int index;
        ResourceManager rm = Constant.RM;
        CultureInfo culture = Constant.CULTURE;
        public frmAuditlog(frmMain main, int index)
        {
            this.index = index;
            this.main = main;
            InitializeComponent();
            DataTable dt = auditLogDAO.getAllActionsDetailsByEnglishID("1");
            cboActions.DataSource = dt;
            cboActions.DisplayMember = "Contents";
            cboActions.ValueMember = "ID";
            loadAuditLogData();
            setLanguage();
        }
        /* Author : Jenny
         * Date : 10/4/2012
         * function setLanguage
         * set language
         * no return
         */
        public void setLanguage()
        {
            lblUsername.Text = rm.GetString("lblUsername", culture) + " : ";
            lblDateBegin.Text = rm.GetString("lblDateBegin", culture) + " : ";
            lblDateEnd.Text = rm.GetString("lblDateEnd", culture) + " : ";
            btnSearch.Text = Constant.TAB + rm.GetString("btnSearch", culture);
            btnPreview.Text = Constant.TAB + rm.GetString("btnPreview", culture);
            this.Text = rm.GetString("frmAuditLog", culture);
            dgvAuditLog.DataSource = dt;
            dgvAuditLog.Columns["UserName"].Name = rm.GetString("lblUserName", culture);
            dgvAuditLog.Columns["StaffCode"].Name = rm.GetString("lblStaffCode", culture);
            dgvAuditLog.Columns["FirstName"].Name = rm.GetString("lblFullName", culture);
            dgvAuditLog.Columns["LogDate"].Name = rm.GetString("lblLogDate", culture);
            dgvAuditLog.Columns["LogTime"].Name = rm.GetString("lblLogTime", culture);
            dgvAuditLog.Columns["Actions"].Name = rm.GetString("lblActions", culture);
            dgvAuditLog.Columns["Contents"].Name = rm.GetString("lblContents", culture);
        }
        /* Author : Jenny
         * Date : 3/4/2012
         * function loadAuditLogData
         * get auditlog data and load to datagridview
         * no return 
         */
        public void loadAuditLogData()
        {
            username = txtUserName.Text.Trim();
            fromDate = auditLogDAO.sortDate(dtpFromDate.Value.ToShortDateString());
            endDate = auditLogDAO.sortDate(dtpEndDate.Value.ToShortDateString());
            String status = "1";
            if (chkDate.Checked == true)
                status = "2";
            dt = auditLogDAO.getAuditLogByCondition(username, fromDate, endDate, cboActions.SelectedValue.ToString(), status);
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            loadAuditLogData();
        }

        private void frmAuditlog_FormClosing(object sender, FormClosingEventArgs e)
        {
            //main.Enabled = true;
            main.listOpen.Remove(index);
        }

        private void chkDate_CheckedChanged(object sender, EventArgs e)
        {
            if (chkDate.Checked == true)
            {
                dtpFromDate.Enabled = true;
                dtpEndDate.Enabled = true;
            }
            else
            {
                dtpFromDate.Enabled = false;
                dtpEndDate.Enabled = false;
            }
        }

        private void btnPreview_Click(object sender, EventArgs e)
        {
            //frmAuditLogPreview auditLogPreview = new frmAuditLogPreview(this,dt);
            //auditLogPreview.ShowDialog();
        }

        private void frmAuditlog_Load(object sender, EventArgs e)
        {

        }
   }
}
